const logger = require('log4js').getLogger()

module.exports = (req, res) => {
    require('../util/service').handlePost(req, res, (reqObj, resolve) => {
        if ((!reqObj.taobaoTradeParentId && !reqObj.orderId) || !reqObj.customer_phone) {
            resolve({
                result: -1,
                msg: '缺少参数'
            })
            return
        }
        const mongoMng = require('../mng/mongoMng')
        if (!mongoMng.db) {
            resolve({
                result: -1,
                msg: '系统错误'
            })
            return
        }
        var query = {
            customer_phone: null
        }
        if (reqObj.taobaoTradeParentId) {
            query.taobaoTradeParentId = reqObj.taobaoTradeParentId
        } else if (reqObj.orderId) {
            query.orderId = parseInt(reqObj.orderId)
        }
        logger.debug('[' + __filename + ':' + __line + ']', query)
        mongoMng.db.collection('bill').update(query, {
            $set: {
                customer_phone: reqObj.customer_phone
            }
        }, {
            multi: true
        }, (err) => {
            if (err) {
                logger.error('[' + __filename + ':' + __line + ']', err)
                resolve({
                    result: -1,
                    msg: '系统错误'
                })
                return
            }
            resolve({
                result: 1,
                msg: '成功'
            })
        })
    })
}